package thread;

public class SyncDemo4 {
    public static void main(String[] args) {
        Aoo a = new Aoo();
        new Thread(a::methodA).start();
        new Thread(a::methodB).start();
    }
}

class Aoo {
    public synchronized void methodA() {
        Thread t = Thread.currentThread();
        System.out.println(t.getName() + "正在执行methodA");
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        System.out.println(t.getName() + "执行methodA完毕");
    }

    public synchronized void methodB() {
        Thread t = Thread.currentThread();
        System.out.println(t.getName() + "正在执行methodB");
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        System.out.println(t.getName() + "执行methodB完毕");
    }
}